---
layout: "default"
title: "ObjectIdentifier"
description: "Swift documentation for 'ObjectIdentifier': A unique identifier for a class instance or metatype."
keywords: "ObjectIdentifier,struct,swift,documentation,<,==,debugDescription,hashValue"
root: "/v3.0"
---

<div class="intro-declaration"><code class="language-swift">struct ObjectIdentifier</code></div>

<div class="discussion comment">
    <p>A unique identifier for a class instance or metatype.</p>

<p>In Swift, only class instances and metatypes have unique identities. There
is no notion of identity for structs, enums, functions, or tuples.</p>
</div>

<table class="standard">
<tr>
<th id="inheritance">Inheritance</th>
<td>
<code class="inherits">Comparable, CustomDebugStringConvertible, Equatable, Hashable</code>
<span class="viz"><a href="hierarchy/">View Protocol Hierarchy &rarr;</a></span>
</td>
</tr>



<tr>
<th>Import</th>
<td><code class="language-swift">import Swift</code></td>
</tr>

</table>


<h3>Initializers</h3>
<div class="declaration" id="init_-any-type">
<a class="toggle-link" data-toggle="collapse" href="#comment-init_-any-type">init(<wbr>_: Any.Type)</a><div class="comment collapse" id="comment-init_-any-type"><div class="p">
    <p>Creates an instance that uniquely identifies the given metatype.</p>

<p><strong>Parameter:</strong> A metatype.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">init(_ x: Any.Type)</code>

    </div></div>
</div>
<div class="declaration" id="init_-anyobject">
<a class="toggle-link" data-toggle="collapse" href="#comment-init_-anyobject">init(<wbr>_: AnyObject)</a><div class="comment collapse" id="comment-init_-anyobject"><div class="p">
    <p>Creates an instance that uniquely identifies the given class instance.</p>

<p>The following example creates an example class <code>A</code> and compares instances
of the class using their object identifiers and the identical-to
operator (<code>===</code>):</p>

<pre><code class="language-swift">class IntegerRef {
    let value: Int
    init(_ value: Int) {
        self.value = value
    }
}

let x = IntegerRef(10)
let y = x

print(ObjectIdentifier(x) == ObjectIdentifier(y))
// Prints &quot;true&quot;
print(x === y)
// Prints &quot;true&quot;

let z = IntegerRef(10)
print(ObjectIdentifier(x) == ObjectIdentifier(z))
// Prints &quot;false&quot;
print(x === z)
// Prints &quot;false&quot;</code></pre>

<p><strong><code>x</code>:</strong>  An instance of a class.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">init(_ x: AnyObject)</code>

    </div></div>
</div>


<h3>Instance Variables</h3>
<div class="declaration" id="var-debugdescription_-string">
<a class="toggle-link" data-toggle="collapse" href="#comment-var-debugdescription_-string">var debugDescription: String</a><div class="comment collapse" id="comment-var-debugdescription_-string"><div class="p">
    <p>A textual representation of the identifier, suitable for debugging.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">var debugDescription: String { get }</code>

    </div></div>
</div>
<div class="declaration" id="var-hashvalue_-int">
<a class="toggle-link" data-toggle="collapse" href="#comment-var-hashvalue_-int">var hashValue: Int</a><div class="comment collapse" id="comment-var-hashvalue_-int"><div class="p">
    <p>The identifier&#39;s hash value.</p>

<p>The hash value is not guaranteed to be stable across different
invocations of the same program.  Do not persist the hash value across
program runs.</p>

<p><strong>See Also:</strong> <code>Hashable</code></p>

    <h4>Declaration</h4>    
    <code class="language-swift">var hashValue: Int { get }</code>

    </div></div>
</div>



<h3>Instance Methods</h3>
<div class="declaration" id="func-lt_rhs_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-lt_rhs_">func &lt;(<wbr>_:<wbr>rhs:)</a>
        
<div class="comment collapse" id="comment-func-lt_rhs_"><div class="p">
    <p>Returns a Boolean value indicating whether the value of the first
argument is less than that of the second argument.</p>

<p>This function is the only requirement of the <code>Comparable</code> protocol. The
remainder of the relational operator functions are implemented by the
standard library for any type that conforms to <code>Comparable</code>.</p>

<p><strong>Parameters:</strong>
  <strong>lhs:</strong> A value to compare.
  <strong>rhs:</strong> Another value to compare.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func &lt;(lhs: ObjectIdentifier, rhs: ObjectIdentifier) -&gt; Bool</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-eqeq_y_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-eqeq_y_">func ==(<wbr>_:<wbr>y:)</a>
        
<div class="comment collapse" id="comment-func-eqeq_y_"><div class="p">
    <p>Returns a Boolean value indicating whether two values are equal.</p>

<p>Equality is the inverse of inequality. For any values <code>a</code> and <code>b</code>,
<code>a == b</code> implies that <code>a != b</code> is <code>false</code>.</p>

<p><strong>Parameters:</strong>
  <strong>lhs:</strong> A value to compare.
  <strong>rhs:</strong> Another value to compare.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func ==(x: ObjectIdentifier, y: ObjectIdentifier) -&gt; Bool</code>
    
    
</div></div>
</div>


